#include <stdio.h>
//二分查找
int half_search(int* arr, int k, int size);
int main()
{
    int arr[]={1,2,3,4,5,6,7,8,9,10};
    int sz = sizeof(arr) / sizeof(arr[0]);
    int key = 1;
    int num = half_search(arr, key, sz);
    printf("%d\n", num);
    return 0;
}

int half_search(int* arr, int k, int size)
{
    int left = 0;
    int right = size - 1;
    int middle = 0;

    while (left <= right)
    {   middle = (left + right)>>1;
        if(arr[middle] > k)
            right = middle -1;
        else if(arr[middle] <k)
            left = middle + 1;
        else
            return middle;

    }
    return -1;
}